package com.breeze.components.mybatis.base;

import cn.hutool.core.date.DatePattern;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import io.swagger.v3.oas.annotations.media.Schema;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Data;

/**
 * @author breeze
 */
@Data
public abstract class BaseEntity implements Serializable {

  @Serial private static final long serialVersionUID = 1L;

  @Schema(title = "唯一id", type = "string")
  @JsonSerialize(using = ToStringSerializer.class)
  @Id(keyType = KeyType.Generator, value = "snowIdGenerator")
  private Long id;

  @Schema(description = "创建时间")
  @Column(onInsertValue = "now()")
  @JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
  private LocalDateTime createTime;

  @Schema(description = "更新时间")
  @Column(onUpdateValue = "now()")
  @JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
  private LocalDateTime updateTime;

  @Schema(description = "创建人")
  private Long createBy;

  @Schema(description = "更新人")
  private Long updateBy;

  @Schema(description = "版本号", nullable = true)
  @Column(version = true)
  private Integer version;

  @Schema(title = "是否删除")
  @Column(isLogicDelete = true)
  private Integer deleteFlag;
}
